<template>
    <div>
        <router-link to="/">返回首页</router-link>

        <h2>一个用于计算成本和利润,方便做活动的工具</h2>
        <div>
            <br>

            单个成本:

            <InputNumber  v-model="cost" placeholder="输入成本" ></InputNumber >
            数量
            <InputNumber  v-model="quantity_n" :step="1"  placeholder="数量" ></InputNumber >


            总价递增(毛利润递增)
            <InputNumber  v-model="price_add" placeholder="递增" ></InputNumber ><br>

            佣金比例
            <InputNumber  v-model="brokerage" :step="10"  placeholder="佣金比例" ></InputNumber >
            递增
            <InputNumber  v-model="brokerage_add" placeholder="递增" ></InputNumber >
            <br>

            邮费
            <InputNumber  v-model="postage" :step="0.5" placeholder="邮费,0.5元递增,递增5次" ></InputNumber >
        </div>



        <Table :columns="columns2" :data="data2"></Table>

    </div>
</template>
<script>
    import lodash from 'lodash';
    export default {
        name: '',
        data() {
            return {
                cost: 1,
                price_add:3,
                brokerage: 10,
                brokerage_add: 5,
                postage: 5,
                quantity_n:1

            };
            // 数据
        },
        components: {
            //包含 Vue 实例可用组件的哈希表。
        },
        props: {
            //数据传递
        },
        computed: {
            columns2() {
                let aa = [
                    {
                        title: '成本\\佣金比例',
                        key: 'cost'
                    }
                ]
                for(let  index=0;index<5;index++){
                    aa.push({
                        title:'佣金 :'+((this.brokerage*1)+this.brokerage_add*index)+'%',
                        key: 'brokerage'+index
                    });
                }
                aa.push({
                    title: '到手单个价格',
                    key: 'one_price',
                    width:'80'
                });
                aa.push({
                    title: '总价',
                    key: 'brokerage',
                })
                return aa;
            },
            data2(){
                let gg=[];
                for(let  index0=1;index0<10;index0++){
                    let cost=(this.cost*this.quantity_n)+this.postage;//成本 = 单个成本*数量 +邮费

                    let price=(this.price_add*index0)+cost;

                    price = lodash.ceil(price,5);
                    //第一层循环
                    let ht={
                        'cost':cost,
                        'brokerage':price,
                        'one_price':lodash.ceil(price/this.quantity_n,3)
                    };
                    ht.cellClassName={};
                    for(let  index=0;index<5;index++){
                        let commission_rate = ((this.brokerage * 1) + this.brokerage_add * index);//佣金比例
                        let brokerage = (price / 100 * commission_rate);//佣金数量
                        let profit = price - cost - brokerage ;//利润
                        profit = lodash.ceil(profit, 2);
                        ht['brokerage' + index] = profit;


                        if(profit<0){
                            ht.cellClassName['brokerage'+index]='red-int';
                        }else{
                            ht.cellClassName['brokerage'+index]='bule-int';

                        }

                    }
                    gg.push(ht)
                }

                return gg;
            }
            //计算属性
        },
        methods: {
            //方法
        },

        created() {
            //实例创建完成
        },


    };
</script>
<style>
    .red-int{
        color: red;
    }

    .bule-int{
        color: blue;
    }
</style>